#include "storage_diagnosis.h"

#include <algorithm>
#include <future>
#include <inttypes.h>
#include <stdio.h>
#include <string.h>

#include "base_file_util.h"
#include "base_utils.h"
#include "base_string.h"
#include "base_log.h"
#include "common_shell.h"

#include "storage_manager.h"

namespace El {
namespace Storage {

StorageDiagnosis &StorageDiagnosis::GetInstance()
{
    static StorageDiagnosis instance;
    return instance;
}

bool StorageDiagnosis::Start()
{
    Common::Shell::GetInstance().RegisterCommand("storage",
                                                 std::bind(&StorageDiagnosis::Storage, this, std::placeholders::_1));
    return true;
}

void StorageDiagnosis::Storage(const std::string &args)
{
    std::vector<std::string> vec_args;
    Base::Split(args, " ", vec_args);
    if (vec_args.size() < 1) {
        LOG_ERROR("Invalid args: {}", args.c_str());
        return;
    }

    std::string text = "";
    if (vec_args[0] == "remove") {
        LOG_INFO("开始手动移除设备");
        IStorageManager::GetInstance().RemoveDevice("/dev/sda");
    }
}

} // namespace Storage
} // namespace El